<?php
/**
 * Created by PhpStorm.
 * User: Zhoujinda
 * Date: 2016/3/26
 * Time: 10:47
 */

namespace app\index\domain;

use app\index\domain\BaseDomain;
use app\bbs\api\CoreReportApi;

class CoreReportDomain extends BaseDomain{
    protected $business_code = "coreReport";

    public function report(){

        if(IS_POST){
            $this->checkVersion($this->api_ver);
            addLog("CoreReport/report",$_GET,$_POST,"应用" . $this->client_id . "调用举报接口");

            $type      = $this->_post('report_type',0);
            $type      = intval($type);
            $id        = $this->_post('report_id','','举报ID缺失');
            $uid       = $this->_post('uid','','被举报人ID缺失');
            $op_uid    = $this->_post('op_uid','','举报人ID缺失');
            $reason    = $this->_post('reason','','举报理由缺失');

            if($type === 0){
                $url = C('SITE_URL').'/index.php/Admin/BbsThread/view/tid/'.$id;
                // $msg = '帖子';
            }elseif($type === 1){
                $url = C('SITE_URL').'/index.php/Admin/BbsForumPost/detail/pid/'.$id;
                // $msg = '回复';
            }elseif($type === 2){
                $url = C('SITE_URL').'/index.php/Admin/Gift/view/id/'.$id;
                // $msg = '赠无限';
            }else{
                $this->apiReturnErr('类型错误');
            }
            $uri = 'type='.$type.';id='.$id.';uid='.$uid.';op_uid='.$op_uid;
            $key = md5($uri);
            $r = apiCall(CoreReportApi::GET_INFO,[['urlkey'=>$key],false,'id']);
            if(!$r['status']) $this->apiReturnErr($r['info']);
            if(!empty($r['info'])) $this->apiReturnErr('您已经举报过了');
            //是否举报过
            $entity = array(
                'urlkey'    => $key,
                'type'      => $type,
                'url'       => $url,
                'message'   => $reason,
                'uid'       => $uid,
                'op_uid'    => $op_uid,
                'report_id' => $id,
                'op_time'   => 0, //处理时间
                'op_result' =>'',
                'date_time' => NOW_TIME,//举报时间
            );

            $r = apiCall(CoreReportApi::ADD,array($entity));
            if($r['status']){
                $this->apiReturnSuc('举报成功!');
            }else{
                $this->apiReturnErr($r['info']);
            }
        }else{
            $this->apiReturnErr('只支持POST请求');
        }

    }

}